17. Exercise: findViewById
L1 41 FindViewById SC 1
Now it’s your turn to complete this exercise yourself.
In this exercise, you will use findViewById to get a reference to the button.
1. Set button’s id in the activity_main.xml layout file:
android:id="@+id/roll_button"
2. Use findViewById to get a reference to the button and assign it to an immutable variable called rollButton:
val rollButton: Button = findViewById(R.id.roll_button)
3. (Optional) Dynamically modify the Button view:
Set the button text to "Roll Button"
rollButton.text = "Let's Roll"
Task Description:
Check the steps below as you implement them to complete this exercise.
Task Feedback:
Great job connecting your first button! Now let's make it display a message when the user clicks it!